package cn.tedu.controller;

import cn.tedu.pojo.UserInfo;
import cn.tedu.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

@Controller
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/userLogin")
    public String userLogin(String username,String password){
        System.out.printf("username:"+username+"--->password:"+password);
        Integer result = userInfoService.userLogin(new UserInfo(null,username,password));
        System.out.printf("result:"+result);
        if (result>0){
            return "product_list";
        }
        return "userLogin";
    }

    @PostMapping("/userSingIn")
    public String userSingIn(String username,String password){
        System.out.printf("username:"+username+"--->password:"+password);
        UserInfo userInfo = new UserInfo(UUID.randomUUID().toString().replace("-"," "),
                username,password);
        Integer result = userInfoService.userSingIn(userInfo);
        if (result>0){
            return "userLogin";
        }
        return "userSingIn";
    }

    @GetMapping("/goLogin")
    public String goLogin(){
        return "userLogin";
    }

    @GetMapping("/goSing")
    public String goSing(){
        return "userSingIn";
    }
}
